package com.jl.jlapp.mvp.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.jl.jlapp.R;
import com.jl.jlapp.eneity.EvaluationSubmitResultModel;
import com.jl.jlapp.eneity.ImageBean;
import com.jl.jlapp.eneity.ImgUploadModel;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.popu.ClearHistorySearhPopu;
import com.jl.jlapp.utils.MimeTypeUtils;
import com.jl.jlapp.utils.Tools;
import com.jl.jlapp.utils.loader.Loader;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionNo;
import com.yanzhenjie.permission.PermissionYes;
import com.yanzhenjie.permission.Rationale;
import com.yanzhenjie.permission.RationaleListener;
import com.yzs.imageshowpickerview.ImageShowPickerBean;
import com.yzs.imageshowpickerview.ImageShowPickerListener;
import com.yzs.imageshowpickerview.ImageShowPickerView;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.PicassoEngine;
import com.zhihu.matisse.internal.entity.CaptureStrategy;

import org.reactivestreams.Subscription;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.FlowableSubscriber;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.MultipartBody.Part;
import okhttp3.RequestBody;

public class EditEvaluationActivity
        extends AppCompatActivity
        implements OnClickListener {
    private static final int REQUEST_CODE_CHOOSE = 233;
    ClearHistorySearhPopu clearHistorySearhPopu;
    @BindView(R.id.evaluation_submit)
    TextView commit_view;
    String describeStr = "";
    @BindView(R.id.edit_evaluation_content)
    EditText editEvaluationContent;
    @BindView(R.id.evaluation_star1)
    ImageView evaluationStar1;
    @BindView(R.id.evaluation_star2)
    ImageView evaluationStar2;
    @BindView(R.id.evaluation_star3)
    ImageView evaluationStar3;
    @BindView(R.id.evaluation_star4)
    ImageView evaluationStar4;
    @BindView(R.id.evaluation_star5)
    ImageView evaluationStar5;
    List<ImageBean> list;
    @BindView(R.id.now_evaluation_world)
    TextView nowEvaluationWorld;
    int orderDetailId = 0;
    int orderDetailNum = 0;
    String orderDetailPic = "";
    int orderId = 0;
    MultipartBody.Part[] partList = new MultipartBody.Part[10];
    List<String> picUrlList = new ArrayList();
    @BindView(R.id.it_picker_view)
    ImageShowPickerView pickerView;
    private ProgressDialog progressDialog;
    private RationaleListener rationaleListener = new RationaleListener() {
        public void showRequestPermissionRationale(int paramAnonymousInt, Rationale paramAnonymousRationale) {
            paramAnonymousRationale.resume();
        }
    };
    List<String> realPicUrlList = new ArrayList();
    int score = 5;
    @BindView(R.id.should_evaluation_goods_img)
    ImageView shouldEvaluationGoodsImg;
    List<ImageView> starImageView;
    int userId = 0;

    @PermissionNo(300)
    private void getPermissionNo(List<String> paramList) {
        Toast.makeText(this, "未授权", Toast.LENGTH_SHORT).show();
    }

    @PermissionYes(300)
    private void getPermissionYes(List<String> paramList) {
    }

    private void photo(List<String> paramList) {
        this.partList = new MultipartBody.Part[10];
        int i = 0;
        while (i < paramList.size()) {
            File file = new File((String) paramList.get(i));
            if (file != null) {
                RequestBody localRequestBody = RequestBody.create(MediaType.parse(MimeTypeUtils.getMimeType(file)), file);
                Part part = Part.createFormData("file", file.getName(), localRequestBody);
                this.partList[i] = part;
            }
            i += 1;
        }
    }

    private void submitData() {
        buildProgressDialog();
        this.describeStr = this.editEvaluationContent.getText().toString().trim();
        if (this.userId <= 0) {
            Toast.makeText(this, "内部错误", Toast.LENGTH_SHORT).show();
            cancelProgressDialog();
        }
//        do {
//            return;
//            if (this.score <= 0) {
//                Toast.makeText(this, "请评分", Toast.LENGTH_SHORT).show();
//                cancelProgressDialog();
//                return;
//            }
//            if ("".equals(this.describeStr)) {
//                Toast.makeText(this, "请填写商品评价", Toast.LENGTH_SHORT).show();
//                cancelProgressDialog();
//                return;
//            }
//            if (this.orderDetailId <= 0) {
//                Toast.makeText(this, "页面传值没收到", Toast.LENGTH_SHORT).show();
//                cancelProgressDialog();
//                return;
//            }
//        }
        while ((this.orderDetailId <= 0) || (this.userId <= 0) || (this.score <= 0) || ("".equals(this.describeStr)))
            ;
        Tools.addActivity(this);
        if (this.realPicUrlList.size() > 0) {
            photo(this.realPicUrlList);
            this.commit_view.setClickable(false);
            this.commit_view.setTextColor(getResources().getColor(R.color.font_grey));
            Net.get().uploadPhoto(this.partList).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ImgUploadModel>() {


                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(ImgUploadModel imgUploadModel) {

                }

                @Override
                public void onError(Throwable t) {

                }

                @Override
                public void onComplete() {

                }
            });
            return;
        }
        this.picUrlList = new ArrayList();
        Net.get().commitEvaluation(this.orderDetailId, this.userId, this.describeStr, this.score, this.picUrlList).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<EvaluationSubmitResultModel>() {


            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(EvaluationSubmitResultModel evaluationSubmitResultModel) {

            }

            @Override
            public void onError(Throwable t) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    public void buildProgressDialog() {
        if (this.progressDialog == null) {
            this.progressDialog = new ProgressDialog(this);
            this.progressDialog.setProgressStyle(0);
        }
        this.progressDialog.setMessage("加载中");
        this.progressDialog.setCancelable(true);
        this.progressDialog.show();
    }

    public void cancelProgressDialog() {
        if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
            this.progressDialog.dismiss();
        }
    }

    public void countEditTextNum() {
        this.editEvaluationContent.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable paramAnonymousEditable) {
            }

            public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
            }

            public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
                paramAnonymousInt1 = EditEvaluationActivity.this.editEvaluationContent.getText().toString().length();
                EditEvaluationActivity.this.nowEvaluationWorld.setText(paramAnonymousInt1 + "");
            }
        });
    }

    public String getRealFilePath(Context paramContext, Uri paramUri) {
        if (paramUri == null) {
            return null;
        }

        return "";
//        String str = paramUri.getScheme();
//        Object localObject2 = null;
//        Object localObject3 = null;
//        Object localObject1;
//        if (str == null) {
//            localObject1 = paramUri.getPath();
//        }else  {
//            this.realPicUrlList.add(localObject1);
//            return (String) localObject1;
//            if ("file".equals(str)) {
//                localObject1 = paramUri.getPath();
//            } else {
//                localObject1 = localObject3;
//                if ("content".equals(str)) {
//                    str = paramUri.getAuthority();
//                    if (str.equals("media")) {
//                        paramContext = paramContext.getContentResolver().query(paramUri, new String[]{"_data"}, null, null, null);
//                        localObject1 = localObject3;
//                        if (paramContext != null) {
//                            localObject1 = localObject2;
//                            if (paramContext.moveToFirst()) {
//                                int i = paramContext.getColumnIndex("_data");
//                                localObject1 = localObject2;
//                                if (i > -1) {
//                                    localObject1 = paramContext.getString(i);
//                                }
//                            }
//                            paramContext.close();
//                        }
//                    } else {
//                        localObject1 = localObject3;
//                        if (str.equals("com.jl.jlapp.publish.MyFileProvider")) {
//                            localObject1 = Environment.getExternalStorageDirectory() + "/Pictures/" + paramUri.getLastPathSegment();
//                        }
//                    }
//                }
//            }
//        }
    }

    public void handleImgPicker() {
        this.list = new ArrayList();
        this.pickerView.setImageLoaderInterface(new Loader());
        this.pickerView.setNewData(this.list);
        this.pickerView.setShowAnim(true);
        this.pickerView.setMaxNum(5);
        this.pickerView.setOneLineShowNum(5);
        this.pickerView.setmDelLabel(2131165417);
        this.pickerView.setmAddLabel(2131165621);
        this.pickerView.setmPicSize(200);
        this.pickerView.setPickerListener(new ImageShowPickerListener() {
            public void addOnClickListener(int paramAnonymousInt) {
                if ((ActivityCompat.checkSelfPermission(EditEvaluationActivity.this, "android.permission.READ_EXTERNAL_STORAGE") != 0) || (ActivityCompat.checkSelfPermission(EditEvaluationActivity.this, "android.permission.READ_EXTERNAL_STORAGE") != 0)) {
                    AndPermission.with(EditEvaluationActivity.this).requestCode(300).permission(new String[]{"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"}).rationale(EditEvaluationActivity.this.rationaleListener).callback(this).start();
                    return;
                }
                Matisse.from(EditEvaluationActivity.this).choose(MimeType.of(MimeType.JPEG, new MimeType[]{MimeType.PNG})).countable(true).maxSelectable(paramAnonymousInt + 1).capture(true).captureStrategy(new CaptureStrategy(true, "com.jl.jlapp.publish.MyFileProvider")).restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED).gridExpectedSize(300).thumbnailScale(0.85F).imageEngine(new PicassoEngine()).theme(R.style.Matisse_Dracula).forResult(233);
            }

            public void delOnClickListener(int paramAnonymousInt1, int paramAnonymousInt2) {
                EditEvaluationActivity.this.realPicUrlList.remove(paramAnonymousInt1);
            }

            public void picOnClickListener(List<ImageShowPickerBean> paramAnonymousList, int paramAnonymousInt1, int paramAnonymousInt2) {
                Intent intent = new Intent(EditEvaluationActivity.this, PhotoViewActivity.class);
                intent.putExtra("picUrl", (String) EditEvaluationActivity.this.realPicUrlList.get(paramAnonymousInt1));
                intent.putExtra("flag", 1);
                EditEvaluationActivity.this.startActivity(intent);
            }
        });
        this.pickerView.show();
        AndPermission.with(this).requestCode(300).permission(new String[]{"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.CAMERA"}).rationale(this.rationaleListener).callback(this).start();
        this.pickerView.getDataList();
    }

    protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent) {
        super.onActivityResult(paramInt1, paramInt2, paramIntent);
        if ((paramInt1 == 233) && (paramInt2 == -1)) {
            List<Uri> uris = Matisse.obtainResult(paramIntent);
            if (uris.size() == 1) {
                this.pickerView.addData(new ImageBean(getRealFilePath(this, uris.get(0))));
            } else {
                ArrayList arrayList = new ArrayList();
                Iterator<Uri> iterator = uris.iterator();
                while (iterator.hasNext()) {
                    arrayList.add(new ImageBean(getRealFilePath(this, iterator.next())));
                }
                this.pickerView.addData(arrayList);
            }
        }


    }

    @OnClick({R.id.evaluation_star1, R.id.evaluation_star2, R.id.evaluation_star3, R.id.evaluation_star4, R.id.evaluation_star5, R.id.evaluation_submit, R.id.back})
    public void onClick(View paramView) {
        switch (paramView.getId()) {
            case R.id.evaluation_star1:
                break;
            case R.id.evaluation_star2:
                break;
            case R.id.evaluation_star3:
                break;
            case R.id.evaluation_star4:
                break;
//            do {
//                return;
//                this.score = 1;
//                i = 0;
//                if (i < this.starImageView.size()) {
//                    if (i >= 1) {
//                        break label124;
//                    }
//                    ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_yellow);
//                }
//                for (; ; ) {
//                    i += 1;
//                    break label80;
//                    break;
//                    ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_gray);
//                }
//                this.score = 2;
//                i = 0;
//                if (i < this.starImageView.size()) {
//                    if (i >= 2) {
//                        break label197;
//                    }
//                    ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_yellow);
//                }
//                for (; ; ) {
//                    i += 1;
//                    break label153;
//                    break;
//                    ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_gray);
//                }
//                this.score = 3;
//                i = 0;
//                if (i < this.starImageView.size()) {
//                    if (i >= 3) {
//                        break label270;
//                    }
//                    ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_yellow);
//                }
//                for (; ; ) {
//                    i += 1;
//                    break label226;
//                    break;
//                    ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_gray);
//                }
//                this.score = 4;
//                i = 0;
//            } while (i >= this.starImageView.size());
//            if (i < 4) {
//                ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_yellow);
//            }
//            for (; ; ) {
//                i += 1;
//                break;
//                ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_gray);
//            }
            case R.id.evaluation_star5:
//                this.score = 5;
//                i = 0;
//                while (i < this.starImageView.size()) {
//                    ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_yellow);
//                    i += 1;
//                }
            case R.id.evaluation_submit:

                submitData();
                return;
        }
        String trim = this.editEvaluationContent.getText().toString().trim();
        if ((this.score != 0) || (!"".equals(trim)) || (this.realPicUrlList.size() > 0)) {
            this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, new OnClickListener() {
                public void onClick(View paramAnonymousView) {
                    EditEvaluationActivity.this.clearHistorySearhPopu.dismiss();
                    EditEvaluationActivity.this.finish();
                }
            }, 9);
            this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.edit_evaluation_page), 17, 0, 0);
            return;
        }
        finish();
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.edit_evaluation_item);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        this.orderDetailId = intent.getIntExtra("orderDetailId", 0);
        this.orderDetailPic = intent.getStringExtra("orderDetailPic");
        this.orderDetailNum = intent.getIntExtra("orderDetailNum", 0);
        this.orderId = intent.getIntExtra("orderId", 0);
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", -1);
        countEditTextNum();
        setData();
        handleImgPicker();
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
        if ((paramInt == 4) && (paramKeyEvent.getRepeatCount() == 0)) {
            String str = this.editEvaluationContent.getText().toString().trim();
            if ((this.score != 0) || (!"".equals(str)) || (this.realPicUrlList.size() > 0)) {
                this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, new OnClickListener() {
                    public void onClick(View paramAnonymousView) {
                        EditEvaluationActivity.this.clearHistorySearhPopu.dismiss();
                        EditEvaluationActivity.this.finish();
                    }
                }, 9);
                this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.edit_evaluation_page), 17, 0, 0);
            } else {
                finish();
                return true;
            }
        }
        return super.onKeyDown(paramInt, paramKeyEvent);
    }

    public void setData() {
        this.starImageView = new ArrayList();
        this.starImageView.add(this.evaluationStar1);
        this.starImageView.add(this.evaluationStar2);
        this.starImageView.add(this.evaluationStar3);
        this.starImageView.add(this.evaluationStar4);
        this.starImageView.add(this.evaluationStar5);
        int i = 0;
        while (i < this.starImageView.size()) {
            ((ImageView) this.starImageView.get(i)).setImageResource(R.drawable.star_yellow);
            i += 1;
        }
        Glide.with(this).asBitmap().apply(new RequestOptions().placeholder(R.drawable.img_noimg_xs).error(R.drawable.img_lose_xs)).load("http://117.158.178.202:8001/JLMIS/" + this.orderDetailPic).into(this.shouldEvaluationGoodsImg);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/EditEvaluationActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */